/*
 * Copyright @ 2018 河南雪城软件有限公司  All rights reserved.
 *
 */

package com.hw.one.peach.da.controller;

import com.alibaba.fastjson.JSONObject;
import com.hw.one.client.Client;
import com.hw.one.core.controller.BaseController;
import com.hw.one.core.logger.annotation.SystemLog;
import com.hw.one.core.logger.constant.LogConstants;
import com.hw.one.core.result.MsgResult;

import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 详细描述
 * </p>
 *
 * @author Erick
 * @date 2018/4/17
 */
@RestController
@RequestMapping("calculate")
public class CaculateDataController extends BaseController {

	/**
	 * 根据数据类型生成日数据、周、月数据、年数据
	 *
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "手动触发任务", notes = "根据数据类型生成日数据、周、月数据、年数据", httpMethod = "GET")
	@SystemLog(moduleName = "手动触发任务", description = "根据数据类型生成日数据、周、月数据、年数据", operType = LogConstants.OPER_SELECT)
	@RequestMapping(path = "generate", method = RequestMethod.GET)
	public MsgResult generateDataByDataType(HttpServletRequest request) {
		Map<String, Object> params = wrapParams(request);
		MsgResult result = null;
		try {
			Client c = Client.getInstance();
			String ret = c.execute("calculate-generate", params, new HashMap<String, Object>(), com.hw.one.client.RequestMethod.GET);

			if (ret == null) {
				result = MsgResult.okResult();
			} else {
				JSONObject obj = (JSONObject) JSONObject.parse(ret);
				result = new MsgResult(obj.getString("type"), obj.getString("code"), obj.getString("message"), obj.get("data"));
			}
		} catch (Exception e) {
			log.error("根据数据类型生成日数据、周、月数据、年数据", e);
		}
		return result;
	}
}
